package org.jetlinks.community.mstn.handler;

import lombok.Getter;
import lombok.Setter;
import org.hswebframework.utils.StringUtils;
import org.jetlinks.community.mstn.annotation.MstnAssetsController;
import org.jetlinks.community.mstn.exception.MstnAssetsUnknownException;
import org.jetlinks.core.enums.ErrorCode;


/**
 * 资产定义
 * @author zhengzuowei
 */
@Getter
public class MstnAssetsDefine {

    private MstnAssetsController methodAnn;

    private MstnAssetsController typeAnn;

    public void setMethodAnn(MstnAssetsController methodAnn) {
        this.methodAnn = methodAnn;
        if (methodAnn != null){
            this.setCommonAnn(methodAnn);
        }
    }

    public void setTypeAnn(MstnAssetsController typeAnn) {
        this.typeAnn = typeAnn;
        if (typeAnn!=null){
            this.setCommonAnn(typeAnn);
        }

    }

    public void setCommonAnn(MstnAssetsController commonAnn){
        this.type = commonAnn.type();
        this.ignoreQuery = commonAnn.ignoreQuery();
        this.assetObjectIndex = commonAnn.assetObjectIndex();
        this.assetIdIndex = commonAnn.assetIdIndex();
        this.autoBind = commonAnn.autoBind();
        this.autoUnbind = commonAnn.autoUnbind();
    }
    /**
     * 资产类型,类和方法上的注解不能同时为空
     */
    public String type;
    /**
     * 忽略处理动态查询条件，默认值false
     */
    public Boolean ignoreQuery;
    /**
     * 方法参数中,资产对象的索引,默认为-1,表示不使用对象来进行租户相关控制,而使用assetIdIndex()来处理
     */
    public int assetObjectIndex;
    /**
     * 方法参数中,资产ID对应的索引,从0开始. 通常用于 根据id进行某个操作时.比如:根据id查询,根据id修改
     */
    public int assetIdIndex;

    /**
     * 是否自动绑定资产, 通用用于新增数据的时候将新增的实体类自动绑定到用户资产下，默认值false
     */
    public boolean autoBind;

    /**
     * 是否自动解绑, 通用用于删除数据的时候,将资产解绑 ，默认值false
     */
    public boolean autoUnbind;
    public static MstnAssetsDefine of(MstnAssetsController methodAnn, MstnAssetsController typeAnn) {
        MstnAssetsDefine define = new MstnAssetsDefine();
        define.setTypeAnn(typeAnn);
        define.setMethodAnn(methodAnn);
        return define;
    }
}
